const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}

function toDecimal2(x) {   
  var f = parseFloat(x);   
  if (isNaN(f)) {   
      return false;   
  }   
  var f = Math.round(x*100)/100;   
  var s = f.toString();   
  var rs = s.indexOf('.');   
  if (rs < 0) {   
      rs = s.length;   
      s += '.';   
  }   
  while (s.length <= rs + 2) {   
      s += '0';   
  }   
  return s;   
} 

module.exports = {
  formatTime,
  APPID: 'wxa295b5ba89f40221',
  SECRET: '11fc307ae36779affc81a0aaeace7f35',
  MCHID: '1614252433',
  toDecimal2
}
